package com.asset.salesforce.converter;

import com.asset.salesforce.domain.Account;
import com.asset.salesforce.enums.INDUSTRY;
import com.asset.salesforce.enums.TYPE;
import com.asset.salesforce.form.AccountForm;
public class AccountConverter {

	public AccountForm accountConerter(Account account){
		AccountForm accountForm = new AccountForm();
		if(account.getId()!=null){
			accountForm.setId(account.getId());
		}
		
		if(account.getAccountName()!=null){
			accountForm.setAccountName(account.getAccountName());
		}
		if(account.getCompanyName() != null && !account.getCompanyName().equalsIgnoreCase("")){
			accountForm.setCompanyName(account.getCompanyName());
		}
		if(account.getFax()!=null){
			accountForm.setFax(account.getFax());
		}
		if(account.getPhone()!=null){
			accountForm.setPhone(account.getPhone());
		}
		if(account.getMobile()!=null){
			accountForm.setMobile(account.getMobile());
		}
		if(account.getWebSite()!=null){
			accountForm.setWebsite(account.getWebSite());
		}
		if(account.getStreet()!=null){
			accountForm.setStreet(account.getStreet());
		}
		if(account.getState()!=null){
			accountForm.setState(account.getState());
		}
		if(account.getZipCode()!=null){
			accountForm.setZipCode(account.getZipCode());
		}
		if(account.getEmail()!=null){
			accountForm.setEmail(account.getEmail());
		}
	
		if(account.getEmpNum()!=null){
			accountForm.setEmpNum(account.getEmpNum());
		}
		if(account.getAnnualRevenue()!=null){
			accountForm.setAnnualRevenue(account.getAnnualRevenue());
		}
		if(account.getDescription()!=null){
			accountForm.setDescription(account.getDescription());
		}
		if(account.getCountry()!=null){
			accountForm.setCountry(account.getCountry().getId());
		}
		
		if(account.getCity()!=null){
			accountForm.setCity(account.getCity().getId());
		}
		
		INDUSTRY[] industries=	INDUSTRY.values();
		Integer intdustry = 0;
		for(int i =0 ; i<industries.length;i++){
			if(industries[i].getName().equals((String)account.getIndustry())){
				intdustry = i;
			}
		}
//		Integer intdustry = Integer.parseInt(industries[Integer.parseInt(account.getIndustry())].getName());
		accountForm.setIndustry(intdustry);
		TYPE[] types = TYPE.values();
		Integer type = 0;
		for(int i =0 ; i<types.length;i++){
			if(types[i].getName().equals((String)account.getType())){
				type = i;
			}
		}
		accountForm.setType(type);
		return accountForm;
	}
}
